Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify fluid api recognize digit #10308

Merged
merged 5 commits into from
May 7, 2018
Merged

Conversation

jetfuel
Copy link
Contributor

@jetfuel jetfuel commented May 1, 2018

No description provided.

BATCH_SIZE = 64


def inference_network():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename inference_network to inference_program and train_network to train_program? Yi pointed out that "program" is more suitable for Fluid than "network".

acc_val = numpy.array(acc_set).mean()
avg_loss_val = numpy.array(avg_loss_set).mean()
if float(acc_val) > 0.2: # Smaller value to increase CI speed
trainer.params.save(save_dirname)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def event_handler(event):
if isinstance(event, fluid.EndIteration):
print(event.metrics)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change print(event.metrics) to avg_cost, acc = event.values? (e.g., same name as the return value of train_network), and rename avg_loss_val and acc_val below to avg_cost and acc for clarity.

params = fluid.Params(save_dirname)
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()

inferencer = fluid.Inferencer(inference_network, params, place=place)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that the API has changed slightly, please change Inferencer and Trainer's constructor according to https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/fluid/tests/book/word2vec/no_test_word2vec_new_api.py#L118

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Problem, will do

@jetfuel jetfuel force-pushed the simplify_fluid_api_recognize_digit branch from 8f1c70b to e68cc6e Compare May 3, 2018 23:35
@jetfuel
Copy link
Contributor Author

jetfuel commented May 3, 2018

@helinwang Updated according to review.

avg_cost = numpy.array(avg_cost_set).mean()
if float(acc) > 0.2: # Smaller value to increase CI speed
trainer.save_params(save_dirname)
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return actually does not stop training, perhaps remove it.
Not related to this PR, maybe we need a function called trainer.stop_train.

return
else:
print(
'BatchID {1:04}, Test Loss {2:2.2}, Acc {3:2.2}'.format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are 1:04, 2:2.2, 3:2.2 typos?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! They are from the original code. When I removed the first item in the print, I forgot to change the others. Will fix this.


else:
print(
'BatchID {1:04}, Test Loss {2:2.2}, Acc {3:2.2}'.format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are 1:04, 2:2.2, 3:2.2 typos?

helinwang
helinwang previously approved these changes May 4, 2018
Copy link
Contributor

@helinwang helinwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@jetfuel jetfuel force-pushed the simplify_fluid_api_recognize_digit branch from c06e1ef to c10d030 Compare May 7, 2018 18:07
@jetfuel jetfuel merged commit 380471f into develop May 7, 2018
@jetfuel jetfuel deleted the simplify_fluid_api_recognize_digit branch May 7, 2018 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants